// FormWriter Mootools based JavaScript Library.

// TODO: use class FormWriter?

fw_subst = function(id, display, control, url, offset){
  $(id + '_' + display + '_' + control).addEvent('click', function() {
    // TODO: encoding problem
    new Request.HTML({
      url: url + '?fw_o=' + offset,
      method: 'get',
      update: $(id)
    }).send();
  });
};

fw_substs = function(id, display, url, first, current, last, offset, row_cnt, last_offset) {
  offset -= (current - first) * row_cnt;
  for (page = first; page <= last; page++) {
    if (page != current) {
      fw_subst(id, display, page, url, offset);
    } else {
      if (current != first) {
        fw_subst(id, display, 'first', url, 0);
        fw_subst(id, display, 'back', url, offset - row_cnt);
      }

      if (current != last) {
        fw_subst(id, display, 'forward', url, offset + row_cnt);
        fw_subst(id, display, 'last', url, last_offset);
      }
    }

     offset += row_cnt;
  }
};

// TODO: needed?
/*
// Initialize FormWriter when the DOM is ready
window.addEvent('domready', function() {
  // TODO
});
*/

/*
  End of file
  vim: set ts=2 sw=2 et:
*/
